package com.company.module.net.utils;

import android.text.TextUtils;

import com.hjq.toast.ToastUtils;

import java.text.DecimalFormat;

/**
 * Created by liub
 * time 2018/5/15
 */

public class StringUtils {
    /**
     * 字符串是否为空或null
     *
     * @param str
     * @return
     */
    public static boolean isNull(String str) {
        if (TextUtils.isEmpty(str) || "null".equals(str))
            return true;
        return false;
    }

    public static boolean isNullToast(Object str, boolean showT, String msg) {
        if (isNull(str)) {
            if (showT) {
                ToastUtils.show(msg);
            }
            return true;
        }
        return false;
    }

    /**
     * 字符串是否为空或null
     *
     * @param str
     * @return
     */
    public static boolean isNull(Object str) {
        if (null == str || TextUtils.isEmpty(str.toString()) || "null".equals(str) || "".equals(str))
            return true;
        return false;
    }

    /**
     * 字符串是否符合要求
     *
     * @param str   字符串
     * @param mlong 长度
     * @return
     */
    public static boolean isRequire(String str, int mlong) {
        if (TextUtils.isEmpty(str) || "null".equals(str) || str.length() != mlong)
            return false;
        return true;
    }

    public static String getFormat(float account_money) {
        if (account_money == 0) {
            return "0.00";
        }
        return new DecimalFormat("0.00").format(account_money);
    }

    public static String getFormat4(float account_money) {
        if (account_money == 0) {
            return "0.0000";
        }
        return new DecimalFormat("0.0000").format(account_money);
    }
}
